<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="支付类型 0-微信支付 1-支付宝支付" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="paymentType">
              <j-dict-select-tag type="list" v-model="model.paymentType" dictCode="payment_type" placeholder="请选择支付类型 0-微信支付 1-支付宝支付" disabled/>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="支付状态：0-待支付、1-已支付 2-已取消" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="paymentStatus">
              <j-dict-select-tag type="list" v-model="model.paymentStatus" dictCode="payment_status" placeholder="请选择支付状态：0-待支付、1-已支付 2-已取消" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="支付编号(交易流水号)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="paymentSn">
              <a-input v-model="model.paymentSn" placeholder="请输入支付编号(交易流水号)" disabled ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="订单ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="orderId">
              <a-input v-model="model.orderId" placeholder="请输入订单ID" disabled ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="支付者ID（微信为OpenID，支付宝为OpenID）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="payerId">
              <a-input v-model="model.payerId" placeholder="请输入支付者ID（微信为OpenID，支付宝为OpenID）" disabled ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="交易ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="transactionId">
              <a-input v-model="model.transactionId" placeholder="请输入交易ID" disabled ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="订单OrderSN，用于第三方交易" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="outTradeNo">
              <a-input v-model="model.outTradeNo" placeholder="请输入订单OrderSN，用于第三方交易" disabled ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="支付金额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="amount">
              <a-input-number v-model="model.amount" placeholder="请输入支付金额" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="支付描述" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="paymentDescription">
              <a-input v-model="model.paymentDescription" placeholder="请输入支付描述"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="平台商户名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="platformmerchantname">
              <a-input v-model="model.platformmerchantname" placeholder="请输入平台商户名"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="分页页数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="pageNo">
              <a-input-number v-model="model.pageNo" placeholder="请输入分页页数" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="分页大小" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="pageSize">
              <a-input-number v-model="model.pageSize" placeholder="请输入分页大小" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'HTPaymentForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
            paymentType:0,
            paymentStatus:0,
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
           paymentType: [
              { required: true, message: '请输入支付类型 0-微信支付 1-支付宝支付!'},
           ],
           paymentStatus: [
              { required: true, message: '请输入支付状态：0-待支付、1-已支付 2-已取消!'},
           ],
           paymentSn: [
              { required: true, message: '请输入支付编号(交易流水号)!'},
           ],
           orderId: [
              { required: true, message: '请输入订单ID!'},
           ],
           amount: [
              { required: true, message: '请输入支付金额!'},
           ],
           paymentDescription: [
              { required: true, message: '请输入支付描述!'},
           ],
           platformmerchantname: [
              { required: true, message: '请输入平台商户名!'},
           ],
        },
        url: {
          add: "/payment/hTPayment/add",
          edit: "/payment/hTPayment/edit",
          queryById: "/payment/hTPayment/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>